package com.itwn.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itwn.entity.Cinema;
import com.itwn.mapper.CinemaMapper;
import com.itwn.vo.CinemaVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CinemaService {
    private CinemaMapper cinemaMapper;

    @Autowired
    public CinemaService(CinemaMapper cinemaMapper) {
        this.cinemaMapper = cinemaMapper;
    }
    public List<Cinema> findAllCinemas(){
        return cinemaMapper.selectAll();
    }
    public int findCinemaHallId(Integer cinemaId,Integer htId) {
        return cinemaMapper.findCinemaHallId(cinemaId, htId);
    }

    public PageInfo<Cinema> findByCon(Integer pageNum,Integer pageSize,String name,String phone,String area){
        PageHelper.startPage(pageNum, pageSize);
        List<Cinema> cinemas = cinemaMapper.selectByCon(name, phone, area);
        PageInfo<Cinema> pageInfo = new PageInfo<>(cinemas);
        return pageInfo;
    }

    public int removeCinemaById(Integer id) {
        int i = cinemaMapper.updateStateById(id);
        return i;
    }

    public int addCinema(Cinema cinema){
        int insert = cinemaMapper.insert(cinema);
        return insert;
    }

    public int updateCinema(Cinema cinema) {
        int insert = cinemaMapper.updateByPrimaryKey(cinema);
        return insert;
    }

    public List<Cinema> findOneByName(String cinemaName) {
        List<Cinema> cinemas = cinemaMapper.selectByCon(cinemaName, null, null);
        return cinemas;
    }
}
